#!/usr/bin/env bash

source scripts/_var.sh
source scripts/_fn.sh

REPO_DIR=$(realpath ./dist)
mkdir -p "$REPO_DIR"
rm "$REPO_DIR"/report.json

while read -r line
do
  pushd "$(dirname "$line")" > /dev/null || exit
    while read -r mod
    do
      echo "testing $mod"
      go test -json -coverprofile="$REPO_DIR"/"$(basename $mod)".coverage.out "$mod" >> "$REPO_DIR"/report.json
    done < <(go list ./...)
    status=$?
    [[ $status -eq 0 ]] || exit $status
  popd > /dev/null || exit
done < <(list_go_mod)
